import 'package:flutter/material.dart';
import 'package:my_flutter_tool/util/app_util.dart';
import 'package:my_flutter_tool/widgets/simple_btn.dart';

///提示对话框
class Tips extends StatefulWidget {
  const Tips({
    Key key,
    this.title,
    this.content,
    this.onCheck,
    this.onCancel,
    this.checkText = "确认",
    this.cancelText = "取消",
    this.bottom = false,
  }) : super(key: key);

  ///标题
  final String title;

  ///内容
  final String content;

  ///确认事件
  final Function onCheck;

  ///取消事件
  final Function onCancel;

  ///确认按钮文字
  final String checkText;

  ///取消按钮文字
  final String cancelText;

  ///底部布局
  final bool bottom;

  @override
  _TipsState createState() => _TipsState();
}

class _TipsState extends State<Tips> {
  @override
  Widget build(BuildContext context) {
    return Column(children: [
      if (widget.bottom) _button,
      _title,
      _content,
      if (!widget.bottom) _button,
    ]);
  }

  ///构建标题
  Widget get _title => Padding(
        padding: EdgeInsets.symmetric(horizontal: 80.w),
        child: Text(
          widget.title,
          style: TextStyle(
            fontSize: 60.sp,
            fontWeight: FontWeight.bold,
          ),
        ),
      );

  ///构建内容
  Widget get _content => Padding(
        padding: EdgeInsets.symmetric(horizontal: 80.w),
        child: Text(
          widget.content,
          style: TextStyle(
            fontSize: 50.sp,
          ),
        ),
      );

  ///构建按钮
  Widget get _button => Padding(
        padding: EdgeInsets.symmetric(
            horizontal: 40.w, vertical: widget.bottom ? 0 : 20.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            SimpleBtn(
              text: widget.checkText,
              style: TextStyle(
                color: Theme.of(context).accentColor,
                fontSize: 50.sp,
              ),
              color: Colors.white,
              padding: EdgeInsets.symmetric(horizontal: 100.w, vertical: 20.w),
              onPressed: () {
                if (widget.onCheck != null) widget.onCheck();

                A.back(context, value: true);
              },
            ),
            if (widget.onCancel != null)
              SimpleBtn(
                text: widget.cancelText,
                color: Colors.white,
                style: TextStyle(
                  color: Theme.of(context).accentColor,
                  fontSize: 50.sp,
                ),
                padding:
                    EdgeInsets.symmetric(horizontal: 100.w, vertical: 20.w),
                onPressed: () {
                  widget.onCancel();
                  A.back(context, value: false);
                },
              ),
          ],
        ),
      );
}
